package com.example.studykotlin.kotlin_actual_combat.art.aidl.binderPool;

import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.example.studykotlin.Path;
import com.example.studykotlin.databinding.ActivityBinderPoolBinding;

@Route(path = Path.binder_pool)
public class BinderPoolActivity extends AppCompatActivity {
    private static final String TAG = "BinderPoolActivity";
    ActivityBinderPoolBinding binding;
    private ISecurityCenter mSecurityCenter;
    private ICompute mCompute;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityBinderPoolBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        new Thread(new Runnable() {
            @Override
            public void run() {
                doWork();
            }
        }).start();
    }

    private void doWork() {
        BinderPool binderPool = BinderPool.getInstance(this);
        IBinder securityBinder = binderPool.queryBinder(BinderPool.BINDER_SECURITY_CENTER);
        mSecurityCenter = SecurityCenterImpl.asInterface(securityBinder);
        Log.d(TAG, "visit ISecurityCenter");
        String msg = "helloworld-安卓";
        Log.e(TAG, "content:" + msg);
        try {
            String password = mSecurityCenter.encrypt(msg);
            Log.e(TAG, "encrypt:" + password);
            Log.e(TAG, "decrypt:" + mSecurityCenter.decrypt(password));
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }
}